package custom_class;


/**
 * 自定义数据类型，用于多样测试
 * @author wenyuan
 * @version 1.0
 * @date 2023/7/18
 * @since 8
 */
public class Person implements Comparable<Person> {
    private int height;
    private double weight;
    private int age;
    private String sex;

    public Person(){}

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Person(int height, double weight, int age, String sex) {
        this.height = height;
        this.weight = weight;
        this.age = age;
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "custom_class.Person{" +
                "height=" + height +
                "cm, weight=" + weight +
                "kg, age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }

    public Person clone(){
        try {
            return (Person) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    public int compareTo(Person o) {
        if(this.getAge() > o.getAge())
            return 1;
        else if(this.getAge() < o.getAge()) return -1;
        else return 0;
    }


    @Override
    public boolean equals(Object obj) {
        Person person = null;
        if(obj instanceof Person){
            person = (Person) obj;
        }
        return this.getAge() == person.getAge();
    }
}
